package com.iot.device.service.impl;

import com.iot.device.domain.GasClient;
import com.iot.device.dto.GasClientDataStatistics;
import com.iot.device.mapper.GasClientMapper;
import com.iot.device.mapper.StatisticsMapper;
import com.iot.device.service.IGasClientService;
import com.iot.device.service.IStatisticsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 燃气监测设备Service业务层处理
 * 
 * @author iot
 * @date 2023-04-14
 */
@Service
public class StatisticsServiceImpl implements IStatisticsService
{
    @Autowired
    private StatisticsMapper statisticsMapper;

    @Override
    public Map<String, Long> statisticsTotalGasEvent(Long userId, Date todayStart, Date monthStart){
        Map<String, Long> map = statisticsMapper.statisticsTotalGasEvent(userId, todayStart, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("todayCount", 0L);
            map.put("monthCount", 0L);
            map.put("totalCount", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsTotalGasEventGroupByType(Long userId) {
        Map<String, Long> map = statisticsMapper.statisticsTotalGasEventGroupByType(userId);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsTodayGasEventGroupByType(Long userId, Date todayStart) {
        Map<String, Long> map = statisticsMapper.statisticsTodayGasEventGroupByType(userId, todayStart);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsMonthGasEventGroupByType(Long userId, Date monthStart) {
        Map<String, Long> map = statisticsMapper.statisticsMonthGasEventGroupByType(userId, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public List<Map<String, Object>> selectGasEventTrendStatisticsByDuration(Date startTime, Date endTime, Long userId) {
        return statisticsMapper.selectGasEventTrendStatisticsByDuration(startTime, endTime, userId);
    }

    @Override
    public Map<String, Object> selectGasEventThisYearStatistics(Long userId, Date todayStart, Date monthStart) {
        Map<String, Object> map = statisticsMapper.selectGasEventThisYearStatistics(userId, todayStart, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("todayPosition", 0);
            map.put("todayAngle", 0);
            map.put("todayIi", 0);
            map.put("monthPosition", 0);
            map.put("monthIi", 0);
            map.put("monthAngle", 0);
            map.put("lastMonthPosition", 0);
            map.put("lastMonthIi", 0);
            map.put("lastMonthAngle", 0);
            map.put("yearPosition", 0);
            map.put("yearAngle", 0);
            map.put("yearIi", 0);
            map.put("totalPosition", 0);
            map.put("totalAngle", 0);
            map.put("totalIi", 0);
        }
        return map;
    }

    @Override
    public List<GasClientDataStatistics> selectGasClientDataStatistics(Long userId, int hourLimit, Long deptId) {
        return statisticsMapper.selectGasClientDataStatistics(userId, hourLimit, deptId);
    }


    @Override
    public Map<String, Long> statisticsTotalQuakeEvent(Long userId, Date todayStart, Date monthStart){
        Map<String, Long> map = statisticsMapper.statisticsTotalQuakeEvent(userId, todayStart, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("todayCount", 0L);
            map.put("monthCount", 0L);
            map.put("totalCount", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Object> selectQuakeEventThisYearStatistics(Long userId, Date todayStart, Date monthStart){
        Map<String, Object> map = statisticsMapper.selectQuakeEventThisYearStatistics(userId, todayStart, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("todayPosition", 0);
            map.put("todayAngle", 0);
            map.put("todayIi", 0);
            map.put("monthPosition", 0);
            map.put("monthIi", 0);
            map.put("monthAngle", 0);
            map.put("lastMonthPosition", 0);
            map.put("lastMonthIi", 0);
            map.put("lastMonthAngle", 0);
            map.put("yearPosition", 0);
            map.put("yearAngle", 0);
            map.put("yearIi", 0);
            map.put("totalPosition", 0);
            map.put("totalAngle", 0);
            map.put("totalIi", 0);
        }
        return map;
    }

    @Override
    public List<Map<String, Object>> selectQuakeEventTrendStatisticsByDuration(Date startTime, Date endTime, Long userId) {
        return statisticsMapper.selectQuakeEventTrendStatisticsByDuration(startTime, endTime, userId);
    }
    @Override
    public Map<String, Long> statisticsTotalQuakeEventGroupByType(Long userId) {
        Map<String, Long> map = statisticsMapper.statisticsTotalQuakeEventGroupByType(userId);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsTodayQuakeEventGroupByType(Long userId, Date todayStart) {
        Map<String, Long> map = statisticsMapper.statisticsTodayQuakeEventGroupByType(userId, todayStart);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsMonthQuakeEventGroupByType(Long userId, Date monthStart) {
        Map<String, Long> map = statisticsMapper.statisticsMonthQuakeEventGroupByType(userId, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }


    @Override
    public Map<String, Long> statisticsTotalBeidouEvent(Long userId, Date todayStart, Date monthStart){
        Map<String, Long> map = statisticsMapper.statisticsTotalBeidouEvent(userId, todayStart, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("todayCount", 0L);
            map.put("monthCount", 0L);
            map.put("totalCount", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Object> selectBeidouEventThisYearStatistics(Long userId, Date todayStart, Date monthStart){
        Map<String, Object> map = statisticsMapper.selectBeidouEventThisYearStatistics(userId, todayStart, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("todayPosition", 0);
            map.put("todayAngle", 0);
            map.put("todayIi", 0);
            map.put("monthPosition", 0);
            map.put("monthIi", 0);
            map.put("monthAngle", 0);
            map.put("lastMonthPosition", 0);
            map.put("lastMonthIi", 0);
            map.put("lastMonthAngle", 0);
            map.put("yearPosition", 0);
            map.put("yearAngle", 0);
            map.put("yearIi", 0);
            map.put("totalPosition", 0);
            map.put("totalAngle", 0);
            map.put("totalIi", 0);
        }
        return map;
    }

    @Override
    public List<Map<String, Object>> selectBeidouEventTrendStatisticsByDuration(Date startTime, Date endTime, Long userId) {
        return statisticsMapper.selectBeidouEventTrendStatisticsByDuration(startTime, endTime, userId);
    }
    @Override
    public Map<String, Long> statisticsTotalBeidouEventGroupByType(Long userId) {
        Map<String, Long> map = statisticsMapper.statisticsTotalBeidouEventGroupByType(userId);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsTodayBeidouEventGroupByType(Long userId, Date todayStart) {
        Map<String, Long> map = statisticsMapper.statisticsTodayBeidouEventGroupByType(userId, todayStart);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsMonthBeidouEventGroupByType(Long userId, Date monthStart) {
        Map<String, Long> map = statisticsMapper.statisticsMonthBeidouEventGroupByType(userId, monthStart);
        if(map == null){
            map = new HashMap<>();
            map.put("position", 0L);
            map.put("angle", 0L);
            map.put("Ii", 0L);
        }
        return map;
    }

    @Override
    public Map<String, Long> statisticsTotalPressureSensorEvent(Long userId, Date todayStart, Date monthStart) {
        return statisticsMapper.statisticsTotalPressureSensorEvent(userId, todayStart, monthStart);
    }

    @Override
    public Map<String, Long> statisticsTotalPressureSensorEventGroupByType(Long userId) {
        return statisticsMapper.statisticsTotalPressureSensorEventGroupByType(userId);
    }

    @Override
    public Map<String, Long> statisticsTodayPressureSensorEventGroupByType(Long userId, Date todayStart) {
        return statisticsMapper.statisticsTodayPressureSensorEventGroupByType(userId, todayStart);
    }

    @Override
    public Map<String, Long> statisticsMonthPressureSensorEventGroupByType(Long userId, Date monthStart) {
        return statisticsMapper.statisticsMonthPressureSensorEventGroupByType(userId, monthStart);
    }

    @Override
    public List<Map<String, Object>> selectPressureSensorEventTrendStatisticsByDuration(Date startTime, Date endTime, Long userId) {
        return statisticsMapper.selectPressureSensorEventTrendStatisticsByDuration(startTime, endTime, userId);
    }

    @Override
    public Map<String, Object> selectPressureSensorEventThisYearStatistics(Long userId, Date startTime, Date endTime) {
        Map<String, Object> map = statisticsMapper.selectPressureSensorEventThisYearStatistics(userId, startTime, endTime);
        if(map == null){
            map = new HashMap<>();
            map.put("todayLimitAlarmLl", 0);
            map.put("todayLimitAlarmL", 0);
            map.put("todayLimitAlarmH", 0);
            map.put("todayLimitAlarmHh", 0);
            map.put("monthLimitAlarmLl", 0);
            map.put("monthLimitAlarmL", 0);
            map.put("monthLimitAlarmH", 0);
            map.put("monthLimitAlarmHh", 0);
            map.put("lastMonthLimitAlarmLl", 0);
            map.put("lastMonthLimitAlarmL", 0);
            map.put("lastMonthLimitAlarmH", 0);
            map.put("lastMonthLimitAlarmHh", 0);
            map.put("yearLimitAlarmLl", 0);
            map.put("yearLimitAlarmL", 0);
            map.put("yearLimitAlarmH", 0);
            map.put("yearLimitAlarmHh", 0);
        }
        return map;
    }
}
